<?php

Route::group(['prefix' => 'api', 'namespace' => 'Api'], function(){

	Route::group(['namespace' => 'Customer'], function(){
	    require_once('Routes/Api/wechat.php');

	    Route::group(['middleware' => env('APP_ENV') != 'local' ? 'oauth':['test', 'oauth']], function(){

	    	Route::group(['prefix' => 'device'], function(){
	    		require_once('Routes/Api/device.php');
	    	});

	    	Route::group(['prefix' => 'user'], function(){
				//保存用户信息
	    		Route::post('add', 'UserController@addUser');
	    	});
	    });
	});

	Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function(){
		//后台管理登录
		Route::post('login', 'UserController@login');

		Route::group(['middleware' => 'redirect'], function(){
			//修改密码
			Route::post('update-password', 'UserController@updatePassword');
			//修改信息
			Route::post('update', 'UserController@update');
			//根据用户编号获取水机用户信息
			Route::get('user/info', 'UserController@userInfoFindByOpenId');
			//登出
			Route::post('logout', 'UserController@logout');
			Route::group(['middleware' => 'admin'], function(){
				//增加管理员
				Route::post('add', 'UserController@add');
				//删除管理员
				Route::post('delete', 'UserController@delete');
			});
		});
	});
});

Route::group(['namespace' => 'Page'], function(){

	Route::group(['middleware' => env('APP_ENV') != 'local' ? 'oauth':['test', 'oauth']], function(){

		Route::group(['namespace' => 'Customer'], function(){
			Route::group(['prefix' => 'device'], function(){
				//wechat airkiss
				Route::get('/', 'DeviceController@airKiss');
				Route::group(['middleware' => ['offline', 'isBindAnyDevice']], function(){
					//水机首页
				    Route::get('index', 'DeviceController@getState');
					//系统设置
				    Route::get('config', 'DeviceController@unbind');
					//设备信息
				    Route::get('info', 'DeviceController@all');
				});
			});
			Route::group(['prefix' => 'user'], function(){
				//用户信息
				Route::get('info', 'UserController@getInfo');
			});
		});
	});


	Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function(){
		Route::group(['prefix' => 'user'], function(){
			//登录页面
			Route::get('login', 'UserController@login');
			
			Route::group(['middleware' => 'redirect'], function(){
				//管理员列表
				Route::get('index', 'UserController@index');
				//水机用户信息列表
				Route::get('info-list', 'UserController@userInfoList');
				//管理员编辑
				Route::get('edit', 'UserController@edit');

				Route::group(['middleware' => 'admin'], function(){
					//增加管理员页面
					Route::get('add', 'UserController@add');
				});
				//管理员修改密码
				Route::get('update-password', 'UserController@updatePassword');
			});
		});

		Route::group(['prefix' => 'device', 'middleware' => 'redirect'], function(){
			//设备列表
			Route::get('index', 'DeviceController@index');
			//设备信息历史记录
			Route::get('history', 'DeviceController@history');
		});
	});

});

Route::get('url', '\App\Http\Controllers\Api\Customer\WeChatController@createMenu');